//index.js
const app =getApp()
//图片和视频的路径↓ 没用了
// const url = 'https://xitoss.oss-cn-shanghai.aliyuncs.com/appointMiniImg/';
// https://xit-edu.cn/oss/
const url = 'https://xit-edu.cn/oss/appointMiniImg/';
const urlVenue = url + 'introduceImg/1/';
const urlGardens = url + 'introduceImg/2/';
const urlBuild = url + 'introduceImg/3/';
const urlCollage = url + 'introduceImg/4/';
const urlBookCollage = url + 'introduceImg/5/';
const urlFood = url + 'introduceImg/6/';
const urlParking = url + 'introduceImg/7/';
const urlElse = url + 'introduceImg/8/';

let animationShowHeight = 0;

// animation.translateY(-350).step() 动画主要时因为这个 他会改变绝对值
const dataManager = require('../../../data/visitSchoolDatas/vistSchoolData')
let TopDataChildren
Page({
  data: {
    app:app,
    selectTitle: '推荐路线',
    selectIntroduceTitle:'',
    scroll: true,
    //这个值在下面赋一次，弹窗的资料
    list: [{
      text: '图书馆',
      imgSrc: urlVenue + '1/1.jpg',
      targetId: 0
    }],
    listTop: [{title:'推荐路线'}],
    rotate: "",
    show: false,//底部弹窗
    animationData: "",
    showModalStatus: true,
    showVisitSchoolPanel2: true,
  },
  //路线规划
  DirectionRoute(e) {
    const newEvent = {
      ...e,
      donotLeave: true
    };
    // 读取新添加的属性值
    // const addedValue = newEvent.donotLeave;
    this.selectIntroduce(newEvent)
    this.hideModal()
    this.selectComponent('#map').DirectionRoute(e.currentTarget.dataset.info)
  },
  //现在是变颜色而已
  selectIntroduce(e) {
    this.setData({
      selectIntroduceTitle:e.currentTarget.dataset.info.text
    })
  },
  //选择顶部
  selectTop(e) {
    // 手机页面会不渲染    需要多加这一步来刷新页面  以后多调一个函数刷新就可以了 不必麻烦
    const selectTitle = e.currentTarget.dataset.info
    this.setData({
      selectTitle:selectTitle,
      scroll: true,
      showVisitSchoolPanel2: false,
      show: false,
      list: null
    })

    
    if (selectTitle == '推荐路线') {
      this.a()
      this.setData({
        showVisitSchoolPanel2: true,
        show: false,
      })
    } else{
      this.setData({
        show:true,
        list:TopDataChildren[selectTitle]
      })
    }
  },
  //父子通信 传递数据 顶部导航栏 推荐路线等的切换 panel的切换 selectBottom
  fatherAndChild(e) {
    // console.log(e.detail.value)
    const str = e.detail.value
    // if (str == '精华路线') {
      this.selectComponent('#map').changeRoute(str)
    // } else if (str == '经典路线') {
    //   this.selectComponent('#map').changeRoute(str)
    // } else if (str == '深层路线') {
    //   this.selectComponent('#map').changeRoute(str)
    // }
  },


  modalControll() {
    if (this.data.showModalStatus) {
      this.hideModal()
    } else {
      this.showModal()
    }
  },
  showModal: function () {
    // 显示遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    // animation.translateY(animationShowHeight).step()
    this.setData({
      // animationData: animation.export(),
      showModalStatus: true,
      rotate: ""
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export()
      })
    }.bind(this), 0) //增加秒数会那个啥
  },
  hideModal: function () {
    // this.setData({
    //   marginTop: "180%"
    // })
    // 隐藏遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation;
    animation.translateY(animationShowHeight).step()
    this.setData({
      animationData: animation.export(),
    })
    setTimeout(function () {
      animation.translateY('650rpx').step()
      this.setData({
        animationData: animation.export(),
        showModalStatus: false,
        rotate: "rotate(180deg);"
      })
    }.bind(this))
  },
  a() {
    this.setData({
      showTempRouter: true
    })
  },
  onShareAppMessage: function () {
    var title = '厦工地图';
    var path = '/packageMap/pages/visitSchool/visitSchool.wxml';
    // var imageUrl = '/images/share.png';
    return {
      title: title,
      path: path,
      // imageUrl: imageUrl
    }
  },
  onShareTimeline(){
    wx.shareTimeline({
      title: '逛逛厦工',
      success: function () {
        console.log('分享到朋友圈成功');
      },
      fail: function () {
        console.log('分享到朋友圈失败');
      }
    })
  },
 
  onShow: function () {
    let that = this;
    wx.getSystemInfo({
      success: function (res) {
        animationShowHeight = res.windowHeight;
      }
    })
  },
  onLoad(){
    TopDataChildren = dataManager.getTopDataChildren()
    this.setData({
      listTop:dataManager.getTopData()
    })
  }

})